package com.yifi.system.controller;

import com.auth0.jwt.interfaces.Claim;
import com.jfinal.core.Path;
import com.yifi.common.base.BaseController;
import com.yifi.common.utils.JWTUtils;

import java.util.Map;

/**
 * Content: 外部链接跳转，配置  open_menu?url=http://www.baidu.com；自动跳转
 * Author: 姚善利
 * Date: 2022/3/16 17:29
 */
@Path(value = "/open_menu",viewPath = "/")
public class open_menu_controller extends BaseController {

    //验证跳转链接
    public void index()
    {
        String url=getPara("url","");
        if(url.contains("?"))
        {
            url+="&token="+getSessionAttr("token");
        }
        else
        {
            url += "?token=" + getSessionAttr("token");
        }
        redirect(url);
    }

    //验证token是否有效
    public void checkToken()
    {
        String token=getPara("token","");
        Map<String, Claim> map=JWTUtils.verifyToken(token);
        if(map.size()>0)
        {
            renderJson(success("成功！"));
        }
        else
        {
            renderJson(error("失败！"));
        }
    }
}
